<html>
<head><meta charset="utf-8"><title>Iterator nomenclature · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html">Iterator nomenclature</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="245579964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245579964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245579964">(Jul 11 2021 at 00:50)</a>:</h4>
<p>Looking through the <code>core::iter</code> module description I am missing some terms to describe parts of a chain of iterator adapters.</p>
<p>The java stream package distinguishes "source", "intermediate operation", "terminal operation" and calls the whole assembly "pipeline". We have "adapter" for "intermediate operation", but the other pieces are missing in the public documentation.<br>
I have already used some of the other javaisms in internal documentation for <code>SourceIter</code>. Can I make them part of the public documentation or are there other names that have been used somewhere?</p>
<p>Being able to name concepts is useful.</p>



<a name="245580103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580103">(Jul 11 2021 at 00:55)</a>:</h4>
<p>Bikeshed: "terminal operation" doesn't sound as good if you're using "adapter" instead of "intermediate operation".</p>



<a name="245580170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580170">(Jul 11 2021 at 00:57)</a>:</h4>
<p>We do have a section on iterators being lazy, but it doesn't name the category of things that aren't lazy.</p>



<a name="245580225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580225">(Jul 11 2021 at 00:58)</a>:</h4>
<p>I think some people like to call the "terminal operation" consumers/consuming operations</p>



<a name="245580396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580396">(Jul 11 2021 at 01:02)</a>:</h4>
<p>That's slightly ambiguous since they don't necessarily consume the iterator. But that criticism would also apply to terminal operation. They do tend to consume some items at least.</p>



<a name="245580407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Yu [they/she] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580407">(Jul 11 2021 at 01:03)</a>:</h4>
<p>accumulator, reduce, fold, etc.; not sure we have an unambiguous single term that covers all of them</p>



<a name="245580460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580460">(Jul 11 2021 at 01:04)</a>:</h4>
<p><span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> iterating method, driver.</p>



<a name="245580737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580737">(Jul 11 2021 at 01:13)</a>:</h4>
<p>I'm confused about "consumer" being a problem. I'd think that we're talking about things that take ownership of the iterator, at which point you can't do anything else with it? I think I'm missing something.</p>



<a name="245580824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580824">(Jul 11 2021 at 01:15)</a>:</h4>
<p>Some of the methods only take <code>&amp;mut self</code> instead of <code>self</code>.</p>



<a name="245580853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580853">(Jul 11 2021 at 01:16)</a>:</h4>
<p>And <code>next()</code> is barely consuming, it's the smallest unit of iteration.</p>



<a name="245580872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580872">(Jul 11 2021 at 01:16)</a>:</h4>
<p>Yeah, fair.</p>



<a name="245580885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245580885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245580885">(Jul 11 2021 at 01:17)</a>:</h4>
<p>I have used "advancing method" in some places.</p>



<a name="245581034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245581034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245581034">(Jul 11 2021 at 01:22)</a>:</h4>
<p>I feel like "consumer" does fit for the ones that take <code>self</code>, but you'd need something self for the ones that take <code>&amp;mut self </code>, and it sounds like you're looking for something that covers both.</p>



<a name="245585276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245585276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245585276">(Jul 11 2021 at 03:26)</a>:</h4>
<p>Just call them "Advancers"; "Consumers" are a subset that advance them entirely?</p>



<a name="245600327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245600327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Frank Steffahn <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245600327">(Jul 11 2021 at 10:30)</a>:</h4>
<p>I have never felt the need to name all possible operations together that advance / consume / whatever-it-is-if-it-isn’t-an-adapter an iterator. I’m interested in realistic or even real examples of using such a term.</p>
<p>Reading Java’s <code>Stream</code> docs, it seems to me like the need to clearly call out “terminal operations” is mostly just due to the fact that the programmer needs to manually make sure to never call more than one “terminal” operation to avoid <code>IllegalStateException</code>. In Rust, you can just do whatever you want, as long as the borrow checker allows it, which includes continuing iteration over the remaining elements after something like <code>find</code> or <code>any</code> was called (I’m not even sure e.g. if that is something that <code>Java</code>’s <code>anyMatch</code> allows or disallows; it calls itself “short-circuiting terminal operation”, reading the docs it feels like continuing iteration afterwards is probably not allowed).</p>



<a name="245601255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245601255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245601255">(Jul 11 2021 at 10:57)</a>:</h4>
<p>I'm writing a proposal on effects of iterators and need to distinguish between the results of things like <code>count()</code>, adapters and more incidental things like <code>clone()</code> in <code>cloned()</code>.</p>



<a name="245613114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Iterator%20nomenclature/near/245613114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Iterator.20nomenclature.html#245613114">(Jul 11 2021 at 15:47)</a>:</h4>
<p>I think for now it makes sense to just come up with terminology that is tailored to your proposal, without worrying about whether it ought to apply more broadly. Java's model may be sufficiently different that trying to port terms over directly might not be an especially good fit</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>